home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / EXEC.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-13  |  4.6 KB  |  133 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. ****************************************************************
  12. * EXEC - Editor Executive Routine & Globals
  13. * Contains main editor loop and universal variables.
  14.  
  15.     xref    g_3,readfile,refresh,set_edit,open_w,cls,cmd_w
  16.     xref    filenm,edit,border_w,set_w
  17.     xdef    query,findpat,reppat,repflag,exec,p_buf,p_cnt
  18.     xdef    used,get_buf
  19.  
  20. #edit.h
  21. #cursor.h
  22.  
  23. BUFS    equ    5        * Max number of open windows
  24.  
  25. *****************************************************************
  26. exec:
  27.     bsr    init        * Initialze local vars
  28.     bsr    cls        * Initialize virtual screen
  29.     move.l    #cmd_w,(a5)    * open command I/O window
  30.     bsr    border_w    * 
  31.     bsr    get_buf        * open buffer
  32. lpx:
  33.     bsr    edit        * do editing
  34.     tst.w    d0        * look at return code
  35.     beq    skx        * non-zero means window commands
  36.     bsr    g_3        * go do window commands
  37.     bra    lpx        * resume edit
  38. * Dump current window
  39. skx:
  40.     move.l    free,a0        * save free list link
  41.     move.l    a5,free        * put current window in free list
  42.     move.l    (a5),a1        * get link to next item in chain
  43.     move.l    a1,used        * put used list back together
  44.     move.l    a0,(a5)        * link to free link
  45. * Relink and Redraw
  46.     tst.l    used        * get top used window pointer
  47.     beq    ed_exit        * quit if no more windows
  48.     bsr    refresh        * redraw the screen
  49.     bra    lpx
  50. ed_exit:
  51.     bsr    cls        * leave screen pretty
  52.     rts            * this is editor exit
  53. *****************************************************************
  54. * GET_BUF - finds and opens the next available window
  55. get_buf:
  56.     tst.l    free        * check for buffer in free list
  57.     beq    no_buf        * jump on no buffer
  58.     move.l    free,a5        * get next free buffer
  59.     move.l    (a5),free    * replace free list link
  60.     move.l    used,(a5)    * link used link
  61.     move.l    a5,used        * replace used list link
  62.     cmp.l    #end_d,defs    * see if we overran defaults
  63.     blt    sk0_gb        * jump if not
  64.     move.l    #s_def,defs    * reset defaults
  65. sk0_gb:
  66.     move.l    defs,a3        * Get default size window address
  67.     addq.l    #8,defs        * move pointer for next time
  68.     move.w    (a3)+,d0    * Get default upper left X
  69.     move.w    (a3)+,d1    * Get default upper left Y
  70.     move.w    (a3)+,d2    * Get default lower right X
  71.     move.w    (a3)+,d3    * Get default lower right Y
  72.     bsr    set_w        * Setup window parameters
  73.     bsr    set_edit    * Setup editor parameters
  74.     bsr    readfile    * Get filename and file
  75.     move.l    #filenm,a0    * Save name of file locally
  76.     lea    fname(a5),a1    * A1 is address where name goes
  77. lp:
  78.     move.b    (a0)+,(a1)+    * We just transfer bytes until
  79.     bne    lp        *  we find a null
  80.     bsr    open_w        * Open the window
  81.     rts
  82. no_buf:
  83. * set correct edit error and return
  84.     rts
  85. *****************************************************************
  86. * INIT - Initializes local variables
  87. init:
  88.     move.l    #cmd_w,a5    * Open command I/O window
  89.     move.w    #0,d0        * set command window limits
  90.     move.w    #0,d1
  91.     move.w    #79,d2
  92.     move.w    #3,d3
  93.     bsr    set_w        * init command window
  94.     clr.b    filenm        * zero out current filename 
  95.     clr.l    used        * Zap the in-use buffer pointer
  96.     move.w    #BUFS-1,d0    * Buffer count
  97.     move.l    #win,a1        * Start the linked list 
  98.     move.l    a1,free        * get the first pointer
  99. lp0_li:
  100.     move.l    a1,a0        * moves pointer up one node
  101.     add.l    #DESC,a1    * calcs address of next buffer
  102.     move.l    a1,(a0)        * loads address of next buffer
  103.     dbra    d0,lp0_li    * loop for BUFS times
  104.     clr.l    (a0)        * mark last buffer as end of list
  105.     move.l    #defaults,defs    * setup default window frame
  106.     rts
  107. *****************************************************************
  108. * Default window corners.
  109. defaults:
  110.     dc.w    lim_lx,lim_uy,lim_rx,lim_ly    * window 1
  111. s_def:
  112.     dc.w    1,5,75,15    * Default size of window 2n
  113.     dc.w    2,7,76,17    * Default size of window 3n
  114.     dc.w    3,10,77,20    * Default size of window 4n
  115.     dc.w    4,12,78,22    * Default size of window 5n
  116. end_d    equ    *
  117. *****************************************************************
  118.     bss
  119. query:    ds.b    80        * g.p. query buffer
  120. findpat:ds.b    80        * find string pattern
  121. reppat:    ds.b    80        * replace string buffer
  122. repflag:ds.w    1        * "replace" request flag
  123. defs    ds.l    1        * current frame default
  124. free:    ds.l    1        * free buffer linked list ptr
  125. used:    ds.l    1        * in-use buffer link pointer
  126. win:    ds.b    DESC*BUFS    * editing buffers & pointers
  127. e_win    equ    *        * end of windows
  128. p_cnt:    ds.w    1        * Char count in paste buffer
  129. p_buf:    ds.b    $10000        * 64K paste buffer
  130.  
  131.     end
  132.